import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Inject, Post, Get, Query, ALL } from '@midwayjs/core';
import { GameRoomInfoEntity } from '../../entity/room';
import { GameRoomInfoService } from '../../service/room';

/**
 * game模块-房间信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info'],
  entity: GameRoomInfoEntity,
  service: GameRoomInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['roomNumber', 'ownerId'],
    fieldEq: ['roomNumber', 'ownerId']
  }
})
export class AppGameRoomInfoController extends BaseController {
  @Inject()
  gameRoomInfoService: GameRoomInfoService;

  @Post('/changeReady', { summary: '修改准备状态' })
  async changeReady(@Body(ALL) param: any,) {
      return this.ok(await this.gameRoomInfoService.changeReady(param));
  }

  @Post('/dissolveRoom', { summary: '解散房间' })
  async dissolveRoom(@Body('id') id: number,) {
      return this.ok(await this.gameRoomInfoService.dissolveRoom(id));
  }

  @Post('/joinRoom', { summary: '加入房间' })
  async joinRoom(@Body('roomNumber') roomNumber: string,) {
      return this.ok(await this.gameRoomInfoService.joinRoom(roomNumber));
  }

  @Post('/leaveRoom', { summary: '离开房间' })
  async leaveRoom(@Body('roomNumber') roomNumber: string,) {
      return this.ok(await this.gameRoomInfoService.leaveRoom(roomNumber));
  }

  @Post('/selectLevel', { summary: '选择关卡' })
  async selectLevel(@Body('id') id: number,) {
      return this.ok(await this.gameRoomInfoService.selectLevel(id));
  }
}
